<!-- Main content -->
@extends('layouts.default')
@section('css')
<link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
{{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
<style>
    .help-block-error{
        color:red;
    }
    table th,table td{
        font-size:14px!important;
    }
</style>
@stop

@section('content')
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">商家入驻管理 / <a class="text-primary" href="{{url('admin/cash/index')}}">商家入驻申请列表</a></h3>
            </div>

            <div class="card-body">
                <div class="card-body">
                    @include('layouts.message')
                    <form action="{{url('admin/hotelowner/apply_list')}}" method="get">
                        <div class="form-row align-items-center">
                            <div class="col-auto">
                                <label class="sr-only" for="inlineFormInput">Name</label>
                                <input name="search_phone" type="text" class="form-control mb-2" value="{{$_GET['search_phone']??''}}" placeholder="手机号">
                            </div>
                            <div class="col-auto">
                                <label class="sr-only" for="inlineFormInput">酒店</label>
                                <select class="form-control mb-2" name="hotel_id">
                                    <option {{gethtmlattribute($_GET['hotel_id']??'-1','-1')}} value="-1" >选择酒店</option>
                                    @foreach($hotel_list as $hotel)
                                        <option value="{{$hotel['hotel_id']}}" {{gethtmlattribute($_GET['hotel_id']??'',$hotel['hotel_id'])}}>{{$hotel['name']}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="col-auto">
                                <label class="sr-only">酒店</label>
                                <select class="form-control mb-2" name="status">
                                    <option {{gethtmlattribute($_GET['status']??'-1','-1')}} value="-1" >选择状态</option>
                                        <option value="0" {{gethtmlattribute($_GET['status']??'',0)}}>申请中</option>
                                        <option value="1" {{gethtmlattribute($_GET['status']??'',1)}}>已入驻</option>
                                        <option value="2" {{gethtmlattribute($_GET['status']??'',2)}}>被拒绝</option>
                                </select>
                            </div>
                            <div class="col-auto">
                                <button type="submit" class="btn btn-primary mb-2">搜索</button>
                            </div>
                        </div>
                    </form>
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>操作</th>
                            <th>申请人手机号</th>
                            <th>酒店名</th>
                            <th>状态</th>
                            <th>申请时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($data['data'] as $v)
                            <tr>
                                <td data-id = {{$v['id']}}>
                                    @if($v['status'] == 0)
                                        <button class="btn btn-primary btn-sm approve">通过</button>
                                        <button class="btn btn-danger btn-sm reject">拒绝</button>
                                    @elseif($v['status'] == 1)

                                    @elseif($v['status'] == 2)

                                    @else

                                    @endif
                                </td>
                                <td>{{$v['phone']}}</td>
                                <td>{{$v['name']}}</td>
                                <td>
                                    @if($v['status'] == 0)
                                        <span style="color:greenyellow">申请中</span>
                                    @elseif($v['status'] == 1)
                                        <span style="color:green">已通过</span>
                                    @elseif($v['status'] == 2)
                                        <span style="color:red">已拒绝</span>
                                    @else
                                        已解绑
                                    @endif
                                </td>
                                <td>{{$v['updated_at']}}</td>


                            </tr>
                        @endforeach
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="5">
                                {{$pages}}
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

@stop



@section('script')
<script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
<script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>

{{--layer插件--}}
<script src='{{asset("admin-lte/plugins/layer-v3.1.1/layer.js")}}' type="text/javascript"></script>
<script>
    var api_update_url = '{{$update_url}}';

    $('.approve').on('click',function(){
        var href = $(this).data('url'),
            $that = $(this);
        layer.confirm('确认要审核通过吗?',function(){
            $.ajax({
                url : api_update_url,
                data : {status:1,id:$that.parent().data('id')},
                type : "GET",
                success:function(data){
                  console.log(data);
                  if(data.ret == 200){
                      layer.alert('审核成功');
                      setTimeout(function(){location.reload()},1500);
                  }else{
                      layer.alert('审核失败');
                  }
                },
            })
        })
    });
    $('.reject').on('click',function(){
        var href = $(this).data('url');
        $that = $(this);
        layer.confirm('确认要拒绝该审核吗?',function(){
            $.ajax({
                url : api_update_url,
                data : {status:2,id:$that.parent().data('id')},
                type : "GET",
                success:function(data){
                    console.log(data);
                    if(data.ret == 200){
                        layer.alert('成功拒绝');
                        setTimeout(function(){location.reload()},1500);
                    }else{
                        layer.alert('拒绝失败');
                    }
                },
            })
        })
    })
</script>
@stop
